<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$query = "select `N`.*,`U`.`login` from `news` as `N`,`users` as `U` where `N`.`user_id` = `U`.`user_id` and `N`.`user_id` = '".$user->getUserId()."' order by `news_id` desc";
$news_list = $db->getTable($query);

$page = UV::readInt(strip_tags($route->GET("page")));
$limit = 10;
$count = count($news_list);
$max_page = ceil($count / $limit);
if ($page < 1)
	$page = 1;
elseif ($page > $max_page)
	$page = $max_page;

$query .= " limit ".($page-1)*$limit.",$limit";
$news_list = $db->getTable($query);

require_once COORDINATOR.DS."head.php";
?>

<div class="submenu_container">
	<a class="submenu_button all_news submenu_button_active" href='/coordinator/content/list'>Список новостей</a>
	<a class="submenu_button add_news" href='/coordinator/content/add'>Добавить новость</a>
</div>
<h3>Список новостей</h3>
<?php
	foreach ($news_list as $news_item)
	{
		?><div class="moderationrecord">
			<div class="recorddate left"><?php echo date("d.m.Y",$news_item['time'])."<br /><span style='font-size:9pt;color:black'>Приоритет: ".$news_item['order']."</span>"; ?></div>
			<div class="record left">
				<div class="recordtitle"><?php echo "<a target='_blank' href='/news/".$news_item['news_id']."-".translitIt($news_item['title'])."'>".$news_item['title']."</a>"; ?></div>
				<div class="recorduser">добавил: <?php echo "<a target='_blank' href='/user/".$news_item['login']."'>".$news_item['login']."</a>"; ?></div>
				<div class="recordtext"><?php echo strip_tags($news_item['preview']); ?></div>
			</div>
			<div class="recordbuttons right">
				<a class="moder_buttons redit" href="/coordinator/content/edit/<?php echo $news_item['news_id']; ?>"></a>
				<a class="moder_buttons rdelete" href="/coordinator/content/delete/<?php echo $news_item['news_id']; ?>"></a>
			</div>
		</div><?php
	}
	echo showPages($count,$limit);
?>

<?php require_once COORDINATOR.DS."footer.php"; ?>
